<template>
	<view class="content">
		<!-- 搜索框 -->
		<!-- <view class="header1">
			<view class="ipt-box">
				<input @input="searChange" v-model="searchIpt" type="text" value="" placeholder="请输入档案号"
					placeholder-class="plac-class" />
				<image src="/static/search1.png" mode="" @click="searNum"></image>
			</view>
			<view class="header1-right" @click="clousText">
				<view class="">取消</view>
			</view>
		</view> -->
		<!-- 气表清零 -->
		<view>
			<view class="ipts" v-if="read_only">
				<view class="record">
					<view class="">
						<image src="/static/jilu.png" mode=""></image>
						<span>用户信息</span>
					</view>
				</view>
				<!-- 户号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>档案号</span>
					</view>
					<span class="place-class">{{list.user_text.meter_num}}</span>
				</view>

				<!-- 户主姓名 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>户主姓名</span>
					</view>
					<span class="place-class">{{list.user_text.realname}}</span>
				</view>

				<!-- 身份证号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>身份证号</span>
					</view>
					<span class="place-class">{{list.user_text.ID_num}}</span>
				</view>

				<!-- 联系方式 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>联系方式</span>
					</view>
					<view class="" style="display: flex;align-items: center;">
						<image src="/static/pagesB/tel.png" mode=""></image>
						<span class="place-class">{{list.user_text.mobile}}</span>
					</view>
				</view>

				<!-- 地址 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>地址</span>
					</view>
					<span class="place-class">{{list.user_text_adress}}</span>
				</view>
			</view>

			<!-- <view class="info-item" v-else>
				<view class="info-item-left">
					<view class="dot"></view>
					<span>身份证号</span>
				</view>
				<input class="item-ipt" type="idcard" v-model="clearDate.ID_num" placeholder="请输入身份证号" />
			</view> -->
			<view class="info-item" v-else>
				<view class="info-item-left">
					<view class="dot"></view>
					<span>输入档案号</span>
				</view>
				<input class="item-ipt" type="text" v-model="clearDate.archives_num" placeholder="请输入档案号" />
			</view>

			<!-- 第二块 -->
			<view class="ipts">
				<!-- 气表清零原因 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>气表清零原因</span>
					</view>
					<input class="item-ipt" type="text" :disabled="read_only" v-model="clearDate.reset_reason"
						placeholder="请输入气表清零原因" />
				</view>

				<!-- 气表品牌 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>气表品牌</span>
					</view>
					<input @tap="show = true" class="item-ipt" type="text" disabled v-model="clearDate.brand"
						placeholder="请选择气表品牌" />
				</view>

				<!-- 气表号 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>气表号</span>
					</view>
					<input class="item-ipt" type="text" :disabled="read_only" v-model="clearDate.gasometer"
						placeholder="请输入气表号" />
				</view>

				<!-- 原气表读数 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>原气表读数</span>
					</view>
					<input class="item-ipt" type="text" :disabled="read_only"
						v-model="clearDate.gasometer_original_number" placeholder="请输入原气表读数" />
				</view>

				<!-- 原气表剩余气量/金额 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>原气表剩余气量/金额</span>
					</view>
					<input class="item-ipt" type="text" :disabled="read_only"
						v-model="clearDate.gasometer_original_price" placeholder="请输入原气表剩余气量/金额" />
				</view>

				<!-- 气表进气方向 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>气表进气方向</span>
					</view>
					<input class="item-ipt" type="text" :disabled="read_only"
						v-model="clearDate.gasometer_original_direction" placeholder="请输入气表进气方向" />
				</view>

				<!-- 气表照片 -->
				<view class="info-item">
					<view class="info-item-left">
						<view class="dot"></view>
						<span>气表照片</span>
					</view>
					<view class="addform-items">
						<template v-for="i,index in clearDate.gasometer_original_images">
							<view class="" style="position: relative;">
								<image class="form-img" :src="i" @tap="seeimg(clearDate.gasometer_original_images,index)"></image>
								<image v-if="!read_only" class="delet" src="/static/delet.png" mode=""
									@tap="deletImg(index)"></image>
							</view>
						</template>
						<view class="add" @tap="choosefrom" v-if="!read_only">
							<u-icon name="camera" color="#999999" size="28"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="btns" v-if="!read_only">
			<view class="btn1 consel" @click="flag= true,searchIpt = ''">取消</view>
			<view class="btn1 save" @click="userPost">保存</view>
		</view>
		<template>
			<u-select v-model="show" value-name='id' label-name="name" @confirm="confirm" :list="gasBrandlist"></u-select>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show:false,
				gasBrandlist:[],
				list: '',
				read_only: false,
				clearDate: {
					ID_num:'',
					archives_num:'',
					reset_reason:'',
					brand:'',
					gasometer:'',
					gasometer_original_number:'',
					gasometer_original_price:'',
					gasometer_original_direction:'',
					gasometer_original_images:[]
				}
			}
		},
		onShow() {},
		onLoad(e) {
			if (e.id) {
				this.read_only = true
				this.initData(e.id)
			}
			this.getGasList()
		},
		methods: {
			confirm(e){
				this.clearDate.brand = e[0].label
			},
			getGasList(){
				var _this = this
				uni.request({
					url: _this.$api + '/Gasbrand/getGasBrandlist',
					method: 'POST',
					header: _this._header,
					success: res => {
						if (res.data.code == 1) {
							_this.gasBrandlist = res.data.data
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			initData(id) {
				var _this = this
				uni.request({
					url: _this.$url + 'gas.clear_gas_record/details',
					method: 'GET',
					data: {
						id: id
					},
					success: (res) => {
						_this.list = res.data.data
						_this.clearDate = res.data.data
						_this.clearDate.gasometer_original_images = _this.clearDate.gasometer_original_images.split(',')
					}
				})
			},
			userPost() {
				var _this = this
				_this.clearDate.gasometer_original_images = _this.clearDate.gasometer_original_images.toString()
				uni.request({
					url: _this.$url + 'gas.clear_gas_record/add',
					method: 'POST',
					header:_this._header,
					data: _this.clearDate,
					success: (res) => {
						_this.$showToast(res.data.msg)
						_this.clearDate.gasometer_original_images = _this.clearDate.gasometer_original_images.split(',')
						if(res.data.code==1){
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},1000)
						}
					}
				})
			},
			seeimg(imgs,index){
				uni.previewImage({
					urls: imgs,
					current:index
				})
			},
			choosefrom() {
				if(this.clearDate.gasometer_original_images.length<3){
					var _this = this
					uni.chooseImage({
						count: 1, //默认9
						sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						success: function(res) {
							uni.uploadFile({
								url: _this.$api + 'common/upload',
								filePath: res.tempFilePaths[0],
								name: 'file',
								header: {
									token: uni.getStorageSync('token')
								},
								success: (uploadFileRes) => {
									if (JSON.parse(uploadFileRes.data).code == 1) {
										_this.clearDate.gasometer_original_images.push(JSON.parse(uploadFileRes.data).data.intact_url) 
									}
								},
								fail: (err) => {
									console.log(err);
								}
							})
						}
					})
				}else{
					uni.showToast({
						icon: 'none',
						title: '上传已达到限制'
					})
				}
				
			},
			deletImg(index){
				this.clearDate.gasometer_original_images.splice(index,1)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.addform-items {
		display: flex;
		align-items: center;

		.form-img {
			width: 60rpx !important;
			height: 60rpx !important;
			margin-right: 20rpx;
		}

		.delet {
			position: absolute;
			top: -8rpx;
			right: 4rpx;
			width: 28rpx;
			height: 28rpx;
			z-index: 10;
		}

		.add {
			width: 60rpx;
			height: 60rpx;
			border: 1rpx solid #DDDDDD;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}

	.content {
		background: #F1F1F1;
		padding-bottom: 100rpx;
		min-height: 100vh;

		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			// padding: 30rpx 30rpx;
			background-color: #fff;

			.header-right {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				color: #333;
				margin-right: 20rpx;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}
			}
		}

		// 搜索框
		.header1 {
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;
			height: 80rpx;
			width: 100%;
			background-color: #003690;
			padding: 0 30rpx;

			.ipt-box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				box-sizing: border-box;
				padding: 0 20rpx;
				width: 480rpx;
				height: 52rpx;
				background-color: #fff;
				border-radius: 24rpx;

				image {
					width: 32rpx;
					height: 32rpx;
				}
			}

			.header1-right {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				color: #E2ECFB;

				image {
					width: 36rpx;
					height: 36rpx;
				}
			}
		}

		.newstyle {
			background: #003690;
			color: #FFFFFF;
		}

		// 气表模块
		.gasmeter {
			display: flex;
			align-items: center;
			// justify-content: space-between;
			// padding: 20rpx 30rpx;
			background: #FFFFFF;
			border-bottom: 1rpx solid #eee;

			.renewal {
				width: 33.3%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
			}

		}


		.searShow {
			width: 360rpx;
			height: 254rpx;
			position: fixed;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);

			image {
				width: 100%;
				height: 100%;
			}
		}

		.dataCont {
			padding-top: 12rpx;
			padding-left: 42rpx;
			padding-right: 30rpx;

			.searTitle {
				font-size: 32rpx;
				font-weight: 600;
				text-align: left;
				color: #333333;
			}

			.searResult {
				display: flex;
				justify-content: space-between;

				.resText {
					font-size: 32rpx;
					font-weight: 400;
					text-align: left;
					color: #777777;
				}

				image {
					width: 36rpx;
					height: 36rpx;
				}
			}
		}

		.ipts {
			background-color: #fff;
			margin-bottom: 20rpx;

			.liaison {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10rpx 30rpx;

				.left {
					display: flex;
					align-items: center;

					.shuxian {
						width: 8rpx;
						height: 28rpx;
						background: #003690;
						opacity: 1;
						border-radius: 200rpx;
						margin-right: 10rpx;
					}

					.name {
						font-size: 28rpx;
						font-family: Source Han Sans SC;
						font-weight: 500;
						color: #333333;
						margin-right: 10rpx;
					}

					.time {
						font-size: 24rpx;
						font-family: Source Han Sans SC;
						font-weight: 400;
						color: #777777;
					}
				}

				.right {
					display: flex;
					align-items: center;

					image {
						width: 32rpx;
						height: 32rpx;
						margin-right: 10rpx;
					}

					.phone {
						font-size: 24rpx;
						font-family: Source Han Sans SC;
						font-weight: 400;
						color: #555555;
					}
				}
			}
		}

		.info-item {
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			// height: 72rpx;
			width: 100%;
			padding: 0rpx 30rpx;
			height: 100rpx;
			align-items: center;
			background-color: #fff;
			font-size: 24rpx;
			color: #333;
			border-bottom: 1rpx solid #DDDDDD;

			image {
				width: 32rpx;
				height: 32rpx;
			}

			input {
				flex: 1;
				text-align: right;
			}

			.dot {
				width: 8rpx;
				height: 8rpx;
				background-color: #003690;
				border-radius: 50%;
				margin-right: 10rpx;
			}

			.danger-img {
				position: relative;
				display: flex;
				align-items: center;

				.updeletes {
					position: absolute;
					top: -20rpx;
					right: -20rpx;
					width: 40rpx;
					height: 40rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					z-index: 88;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.danger-img-box {
				display: flex;

				.danger-img {
					width: 75rpx;
					height: 75rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.danger-img-box2 {
				display: flex;
				align-items: center;

				.danger-img {
					width: 70rpx;
					height: 70rpx;
					// border: 2rpx dashed #eee;

					image {
						width: 70rpx;
						height: 70rpx;
						opacity: 1;
					}
				}
			}

			.info-item-left {
				display: flex;
				align-items: center;
				font-size: 28rpx;
			}
		}

		.hengxian {
			width: 700rpx;
			height: 2rpx;
			background-color: #eee;
			margin: 20rpx auto;
		}

		.place-class {
			font-size: 28rpx;
			color: #999;
		}

		.btn {
			width: 646rpx;
			height: 80rpx;
			margin: 74rpx auto;
			text-align: center;
			line-height: 80rpx;
			border-radius: 40rpx;
			background-image: linear-gradient(to bottom, #2366D5, #001B48);
			font-size: 32rpx;
			color: #E5EFFE;
		}

		.btns {
			position: fixed;
			bottom: 0;
			display: flex;
			width: 100%;
			z-index: 333;

			.btn1 {
				width: 50%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				font-size: 24rpx;
			}

			.consel {
				background-color: #e9e9e9;
				color: #777;
			}

			.save {
				background-color: #003690;
				color: #fff;
			}
		}

		.btn:active {
			background: rgba(0, 0, 0, 0.4);
		}

		.zhanwei {
			height: 250rpx;
		}

		.record {
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #003690;
			font-size: 32rpx;
			padding-top: 20rpx;

			.right {
				width: 394rpx;
				height: 52rpx;
				background: #F2F2F2;
				opacity: 1;
				border-radius: 50rpx;
				padding: 0 10rpx 0 15rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			image {
				width: 32rpx;
				height: 32rpx;
				margin: 0 20rpx 0 30rpx;
			}

			span {
				font-weight: 700;
			}
		}

		.record-item {
			display: flex;
			justify-content: space-between;
			padding: 10rpx 30rpx;
			border-bottom: 2rpx solid #eee;

			.record-item-left {
				display: flex;
				align-items: center;

				.shu {
					width: 8rpx;
					height: 28rpx;
					background-color: #003690;
					border-radius: 8rpx;
				}

				.title {
					font-size: 32rpx;
					color: #333;
					font-weight: 500;
					margin: 0 10rpx;
				}

				.time {
					font-size: 24rpx;
					color: #777;
				}
			}

			.record-item-right {
				display: flex;
				align-items: center;

				.dianhua {
					width: 28rpx;
					height: 28rpx;
				}

				.zhankai {
					width: 36rpx;
					height: 36rpx;
				}

				.title {
					font-size: 32rpx;
					color: #555;
					font-weight: 500;
					margin: 0 10rpx;
				}
			}
		}

		.supplement {
			margin: 20rpx 24rpx;
			background-color: #fff;
			position: relative;
			overflow: hidden;

			.explain {
				.textArea {
					min-height: 142rpx;
					padding: 14rpx 30rpx;
					font-size: 32rpx;
					text-align: left;
					color: rgba(187, 187, 187, 0.84);
				}
			}

			.suppBottom {
				.danger-img {
					position: relative;
					margin-left: 50rpx;
					margin-bottom: 0rpx;
					width: 68rpx;
					height: 68rpx;
					float: left;

					image {
						width: 36rpx;
						height: 36rpx;
						position: absolute;
						left: 50%;
						top: 50%;
						transform: translate(-50%, -50%);
					}
				}

				.num {
					float: right;
					margin-right: 26rpx;
				}
			}
		}
	}
</style>
